home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / SOURCE.BIN / RadioButtonGroupPanel.java < prev    next >
Encoding:
Java Source  |  1997-06-19  |  3.2 KB  |  112 lines

  1. package symantec.itools.awt;
  2.  
  3.  
  4. import java.awt.Panel;
  5. import java.awt.Checkbox;
  6. import java.awt.CheckboxGroup;
  7. import java.awt.Component;
  8.  
  9. //    01/27/97    RKM    Changed moveIntoGroup to preserve checkbox's state
  10. //    01/29/97    TWB    Integrated changes from Windows and RKM's changes 
  11. //     01/29/97    TWB    Integrated changes from Macintosh
  12.  
  13. /**
  14.  * Creates an invisible rectangular panel area that automatically groups 
  15.  * the RadioButtons that it contains.
  16.  * <p>
  17.  * All the RadioButtons within the RadioButtonGroupPanel act together. Only 
  18.  * one of the RadioButtons can be "on" at a time.
  19.  * <p>
  20.  * @version 1.0, Nov 26, 1996
  21.  * @author Symantec
  22.  */
  23.  
  24. public class RadioButtonGroupPanel
  25.     extends Panel
  26. {
  27.     private CheckboxGroup group;
  28.  
  29.     /**
  30.      * Constructs a RadioButtonGroupPanel.
  31.      */
  32.     public RadioButtonGroupPanel()
  33.     {
  34.         group = new CheckboxGroup();
  35.     }
  36.  
  37.     private void moveIntoGroup(Component c)
  38.     {
  39.         if (c instanceof Checkbox)
  40.         {
  41.             //Cast the component to a checkbox
  42.             Checkbox checkBox = ((Checkbox)c);
  43.             
  44.             //Save the state
  45.             boolean savedState = checkBox.getState();
  46.             
  47.             //Set up the checkbox group
  48.             checkBox.setCheckboxGroup(group);
  49.             
  50.             //Restore the state if it was true
  51.             if (savedState)
  52.                 checkBox.setState(savedState);
  53.         }
  54.     }
  55.  
  56.     /**
  57.      * Adds a component to the end of this container.
  58.      * This is a standard Java AWT method which gets called to add a
  59.      * component to a container. The specified component is added to
  60.      * the end of this container.
  61.      *
  62.      * @param c the component to add
  63.      * @return the added component
  64.      * @see java.awt.Container#remove
  65.      */
  66.     public Component add(Component c)
  67.     {
  68.         moveIntoGroup(c);
  69.  
  70.         return super.add(c);
  71.     }
  72.  
  73.     /**
  74.      * Inserts a component into this container at the given position.
  75.      * This is a standard Java AWT method which gets called to add a
  76.      * component to a container. The specified component is added to
  77.      * this container at the given zero-relative position index. A
  78.      * position index of -1 appends the component to the end.
  79.      *
  80.      * @param c the component to add
  81.      * @param p the zero-relative index at which to add the component or -1 for end
  82.      * @return the added component
  83.      * @see java.awt.Container#remove
  84.      */
  85.     public Component add(Component c, int p)
  86.     {
  87.         moveIntoGroup(c);
  88.  
  89.         return super.add(c, p);
  90.     }
  91.  
  92.     /**
  93.      * Adds a component to the end of this container and to the layout manager.
  94.      * This is a standard Java AWT method which gets called to add a
  95.      * component to a container. The specified component is added to
  96.      * the end of this container, and also added to this container's
  97.      * layout manager with the given name.
  98.      *
  99.      * @param s the positioning directive for the layout manager
  100.      * @param c the component to add
  101.      * @return the added component
  102.      * @see java.awt.Container#remove
  103.      */
  104.     public Component add(String s, Component c)
  105.     {
  106.         moveIntoGroup(c);
  107.  
  108.         return super.add(s, c);
  109.     }
  110. }
  111.  
  112.